﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;

namespace ProgNetComponents.Design.Editors
{
    public class ColumnEditor : BaseListEditor
    {
        protected override Dictionary<string, object> GetListBoxItems()
        {
            Dictionary<string, object> l = new Dictionary<string, object>();
            if (_ServiceProvider != null)
            {
                ContainerControl c = null;
                System.ComponentModel.Design.IDesignerHost host = _ServiceProvider.GetService(typeof(System.ComponentModel.Design.IDesignerHost)) as System.ComponentModel.Design.IDesignerHost;
                if (host != null)
                {
                    if (host.RootComponent is ContainerControl)
                        c = host.RootComponent as ContainerControl;
                }
                if (c != null)
                {
                    if (c.Container != null)
                    {
                        for (int i = 0; i < c.Container.Components.Count; i++)
                        {
                            object obj = c.Container.Components[i];
                            if (obj is DataSet)
                            {
                                foreach (DataTable dt in (obj as DataSet).Tables)
                                {
                                    foreach (DataColumn col in dt.Columns)
                                        if (col.ColumnName.IsNotNull() && !l.ContainsKey(col.ColumnName))
                                            l.Add(col.ColumnName, col.ColumnName);
                                }
                            }
                        }
                    }

                }
            }
            return l;
        }
    }
}
